package com.ruoyi.web.controller.operate;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.CompanyProfile;
import com.ruoyi.system.domain.SysInstruction;
import com.ruoyi.system.service.ISysInstructionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 操作指南Controller
 *
 * @author ruoyi
 * @date 2023-07-04
 */
@RestController
@RequestMapping("/operate/instruction")
public class InstructionController extends BaseController
{
    @Autowired
    private ISysInstructionService sysInstructionService;

    /**
     * 查询操作指南列表
     */
    @PreAuthorize("@ss.hasPermi('operate:instruction:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysInstruction sysInstruction)
    {
        startPage();
        List<SysInstruction> list = sysInstructionService.selectSysInstructionList(sysInstruction);
        return getDataTable(list);
    }

    /**
     * 导出操作指南列表
     */
    @PreAuthorize("@ss.hasPermi('operate:instruction:export')")
    @Log(title = "操作指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysInstruction sysInstruction)
    {
        List<SysInstruction> list = sysInstructionService.selectSysInstructionList(sysInstruction);
        ExcelUtil<SysInstruction> util = new ExcelUtil<SysInstruction>(SysInstruction.class);
        util.exportExcel(response, list, "操作指南数据");
    }

    /**
     * 获取操作指南详细信息
     */
    @PreAuthorize("@ss.hasPermi('operate:instruction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysInstructionService.selectSysInstructionById(id));
    }

    /**
     * 新增操作指南
     */
    @PreAuthorize("@ss.hasPermi('operate:instruction:add')")
    @Log(title = "操作指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysInstruction sysInstruction)
    {
        return toAjax(sysInstructionService.insertSysInstruction(sysInstruction));
    }

    /**
     * 修改操作指南
     */
    @PreAuthorize("@ss.hasPermi('operate:instruction:edit')")
    @Log(title = "操作指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysInstruction sysInstruction)
    {
        return toAjax(sysInstructionService.updateSysInstruction(sysInstruction));
    }

    /**
     * 删除操作指南
     */
    @PreAuthorize("@ss.hasPermi('operate:instruction:remove')")
    @Log(title = "操作指南", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysInstructionService.deleteSysInstructionByIds(ids));
    }


    /**
     * 获取操作指南详细信息
     */
    @GetMapping(value = "/getInstructionRecently")
    public AjaxResult getInstructionRecently()
    {
        return success(sysInstructionService.getInstructionRecently());
    }


    /**
     * 修改操作指南状态
     */
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody SysInstruction sysInstruction)
    {
        return toAjax(sysInstructionService.updateStatus(sysInstruction));
    }
}
